const {
  baseUrl,
  getRequest,
  postRequest
} = require("../../../../utils/request.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nickname: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //console.log(options.nickname)
    this.setData({
      nickname: options.nickname
    })
  },
  /**
   * 输入框变化事件
   */
  onInputChange: function (e) {
    console.log(e.detail.value)
    this.setData({
      nickname: e.detail.value,
    });
  },
  /**
   * 修改昵称并跳转到个人详情
   */
  showCourseDesc() {
    wx.getStorage({
      key: "userId",
      success: res => {
        //console.log(res.data)
        postRequest(baseUrl + "/front/user/updateNickname", {
          userId: res.data,
          nickname: this.data.nickname
        }).then(res => {
          if (res.code == 200) {
            wx.showToast({
              title: '修改成功',
              icon: 'success',
              duration: 2000
            })
          }
        })
      }
    })
    wx.navigateTo({
      url: '/pages/user/desc/desc?nickname=' + this.data.nickname,
    })
  },
})